#include "LockImp.h"

LockImp::LockImp()
{
	m_pSem = OS_SemCreate(1);
}

LockImp::LockImp(int i)
{
	m_pSem = OS_SemCreate(i);
}

LockImp::~LockImp()
{
	signal();
	if(m_pSem)
	{		
		OS_SemDestroy(m_pSem);
	}
}

int LockImp::waitTimeOut(unsigned int nTime)
{
	if(OS_SemWait(m_pSem,nTime))
		return -1;

	return 0;
}

void LockImp::signal()
{
	OS_SemSignal(m_pSem);
}

AutoLockImp::AutoLockImp(LockImp& l):m_cLock(l)
{
	m_cLock.waitTimeOut((unsigned int)SEM_WAIT_INFINITE);
}

AutoLockImp::~AutoLockImp()
{
	m_cLock.signal();
}

BaseLock::BaseLock()
{

}

BaseLock::BaseLock(int i ):m_cLock(i)
{
}

BaseLock::~BaseLock()
{
}

int BaseLock::wait(unsigned int nTime)
{
	return m_cLock.waitTimeOut((unsigned int)nTime);
}

void BaseLock::signal()
{
	m_cLock.signal();
}


